package com.java.permission.module.controller;

import com.java.permission.common.dto.SysOfficeDto;
import com.java.permission.common.service.SysOfficeService;
import com.java.permission.common.utils.UserUtils;
import com.java.permission.common.vo.Result;
import com.java.permission.common.vo.SysOfficeTreeVo;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author huxb
 * @date 2020/6/14 0014 下午 12:26
 * @Desciption
 */
@RestController
@RequestMapping("/sys/office")
public class SysOfficeController {
    @Autowired
    private SysOfficeService sysOfficeService;

    /**
     * 新增 编辑部门
     * @param sysOfficeDto
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    public Result saveOrUpdate(SysOfficeDto sysOfficeDto) {
        if (StringUtils.isBlank(sysOfficeDto.getId())) {
            sysOfficeService.save(sysOfficeDto, UserUtils.getUserId());
        } else {
            sysOfficeService.edit(sysOfficeDto, UserUtils.getUserId());
        }
        return Result.success(null);
    }

    /**
     * 获取部门树
     * @return
     */
    @RequestMapping("/tree")
    public Result officeTree() {
        List<SysOfficeTreeVo> sysOfficeTree = sysOfficeService.getSysOfficeTree();
        return Result.success(sysOfficeTree);
    }
}
